<?php
/**
 *
 * @author andrew carlson <andrew@acstudiosllc.com>
 * @version 0.0.1
 * @copyright 2012 ACStudios LLC
 * @package default
 */

namespace Encompass\Accounts;
use PDO;

/**
 * Accounts Model
 *
 * @package default
 * @author  andrew carlson <andrew@acstudiosllc.com>
 */
class accountsModel {
	
	/**
	 * get users from db
	 */
	function list_users() {
		\Encompass\Utilities\utilities::dbConnect();
		$sql = "SELECT user_id, last_name, first_name, email, role_name FROM users 
			LEFT JOIN roles ON roles.role_id = users.role";
		$query = $this->db->query($sql);
		
		$result = $query->fetchAll(PDO::FETCH_ASSOC);
		
		return $result;
	}
	
	
	function addUser($userData) {
		// get a db connector (non-persistent)
		\Encompass\Utilities\utilities::dbConnect();
		
		// sql insert
		$sql = "INSERT INTO users (first_name, last_name, email, role) VALUES (?, ?, ?, ?)";
		
		// prepares sql statement
		$query = $this->db->prepare($sql);
		
		try {
			//attempts insert with array values, this is kinda cheating
			$query->execute($userData);
			$status = "Success";
		} catch (PDOException $e) {
			$status = "Error " . $e->getMessage();
		}
		
		return $status;
	}
	
}
